/*
 * Instruction40.java
 *
 * Created on March 21, 2007, 10:25 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package moto9s12sim;

/**
 *
 * @author Fergus Earnshaw
 */
public class Instruction40 extends Instruction {
    
    /** Creates a new instance of Instruction40 */
    public Instruction40()
    {
        this.strAssemblyCode = "NEGA";
        this.bCodes = new byte[1];
        this.bCodes[0] = (byte)Integer.parseInt("40",16);
    }
    
    public boolean excute(M9S12 cpu)
    {
        this.shAddr = cpu.PC.getRegister();
        cpu.PC.inc();
        
        //INSTRUCTION
          
        cpu.A.setRegister((byte)~cpu.A.getUnsignedRegister());
        cpu.A.inc();
        
        //TO DO set flags
        cpu.CC.setN(cpu.A.getRegister() < 0);
        cpu.CC.setZ(cpu.A.getUnsignedRegister() == 0);
        cpu.CC.setV(cpu.A.getHex() == "80");
        cpu.CC.setC(cpu.A.getHex() != "00");
                
        
        printInstruction(cpu);
        //I think the first invalid instruction should halt excution
        return true;
    }  
    
}